<template>
  <el-rate
    v-model="current_field"
    :colors="colors"
    void-color="#DCDFE6"
    disabled-void-color="#DCDFE6"
    :show-text="showTextValue"
    :show-score="showScoreValue"
    :disabled="disabledValue"
    :allow-half="current_args.half ? true : false"
    :text-color="current_args.textColor ? current_args.textColor : '#606266'"
    score-template="{value}分"
    :max="$util.getDefValue(current_args.max, '5')"
  ></el-rate>
</template>
<script>
export default {
  props: {
    value: {
      default: ''
    },
    args: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      colors: ['#FF8A52', '#FF8A52', '#FF8A52'],
      current_field: this.value,
      current_args: this.args
    }
  },
  computed: {
    showTextValue() {
      if (this.current_args.show_text == '1') {
        return true
      }

      return null
    },
    showScoreValue() {
      if (this.current_args.show_score == '1') {
        return true
      }

      return null
    },
    disabledValue() {
      if (this.current_args.disabled == '1') {
        return true
      }

      return null
    }
  },
  watch: {
    current_field(value) {
      this.$emit('update:value', value)
    },
    value: {
      handler(now, old) {
        this.current_field = now
      }
    }
  }
}
</script>
